package org.dashboard.client.widget;

import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * Created by IntelliJ IDEA.
 * User: g41533
 * Date: 24-02-11
 * Time: 09:21
 * To change this template use File | Settings | File Templates.
 */
public class MultiWidgetHolder extends FlowPanel {

    private final Widget[] widgetsArray;
    private int activeWidget = 0;

    public MultiWidgetHolder(int refreshInterval, Widget... widgets) {
        super();
        this.widgetsArray = widgets;

        for (Widget w : widgets) {
            w.setVisible(false);
            add(w);
        }

        final Timer timer = new Timer() {
            @Override
            public void run() {
                widgetsArray[activeWidget].setVisible(false);
                activeWidget++;
                if (activeWidget >= widgetsArray.length) {
                    activeWidget = 0;
                }
                widgetsArray[activeWidget].setVisible(true);
            }
        };
        timer.scheduleRepeating(refreshInterval);
        timer.run();
    }
}
